package com.smilive.start.netty.netty;

import io.netty.channel.nio.NioEventLoopGroup;

import java.util.concurrent.TimeUnit;

/**
 * @program: netty
 * @Date: 2022-01-05 11:12
 * @Author: smilive
 * @Description:
 */
public class EventLoopTest {

    public static void main(String[] args) {
        NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(2);
        // 通过next方法可以获得下一个 EventLoop
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());

        //执行普通任务
        eventLoopGroup.next().execute(() ->{
            System.out.println(Thread.currentThread().getName()+"普通任务");
        });
        //执行定时任务
        eventLoopGroup.next().scheduleAtFixedRate(() ->{
            System.out.println(Thread.currentThread().getName()+"定时任务");
        },0,1, TimeUnit.SECONDS);

        //优雅关闭
        eventLoopGroup.shutdownGracefully();
    }
}
